<template>
  <div class="header">
    <div class="logo">后台管理系统</div>
    <div class="header-right">
      <div class="header-user-con">
        <div class="btn-fullscreen" @click="handleFullScreen">
          <el-tooltip effect="dark" :content="fullScreen ? '取消全屏' : '全屏'" placement="bottom">
            <el-icon>
              <Rank />
            </el-icon>
          </el-tooltip>
        </div>
        <div class="user-avator">
          <img src="../assets/images/logo_2.png" />
        </div>
        <el-dropdown class="user-name" trigger="click" @command="handleCommand">
          <span class="el-dropdown-link">
            超级管理员
            <i class="el-icon-caret-bottom"></i>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item command="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { ElTooltip, ElIcon, ElDropdown, ElDropdownMenu, ElDropdownItem } from 'element-plus';

const fullScreen = ref(false);
const router = useRouter();

const handleFullScreen = () => {
  const element = document.documentElement;
  if (fullScreen.value) {
    document.exitFullscreen?.() || document.webkitCancelFullScreen?.() || document.msExitFullscreen?.();
  } else {
    element.requestFullscreen?.() || element.webkitRequestFullScreen?.() || element.msRequestFullscreen?.();
  }
  fullScreen.value = !fullScreen.value;
};

const handleCommand = (command) => {
  if (command === 'logout') {
    // 这里可以添加更多的登出逻辑，例如清除 token 等
    router.push('/login');
  }
};
</script>

<style scoped>
.header {
  position: relative;
  width: 100%;
  height: 70px;
  background-color: #6190e8;
  color: #fff;
  margin-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.logo {
  float: left;
  line-height: 70px;
  user-select: none;
  margin-left: 15px;
  font-size: 26px;
}

.header-right {
  float: right;
  padding-right: 20px;
}

.header-user-con {
  display: flex;
  align-items: center;
  height: 70px;
}

.btn-fullscreen {
  transform: rotate(45deg);
  margin-right: 5px;
  font-size: 24px;
  cursor: pointer;
}

.user-name {
  margin-left: 10px;
}

.user-avator {
  margin-left: 10px;
}

.user-avator img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.el-dropdown-link {
  color: #fff;
  cursor: pointer;
  user-select: none;
}
</style>
